home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / lib / gcc-lib / djgpp / 2.952 / units / windos.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2001-02-08  |  8.5 KB  |  256 lines

  1. {
  2. Mostly BP compatible portable WinDos unit
  3.  
  4. This unit supports most, but not all, of the routines and
  5. declarations of BP's WinDos unit.
  6.  
  7. NOTES:
  8.  
  9. - The procedures GetIntVec and SetIntVec are not supported since
  10.   they make only sense for Dos real-mode programs (and GPC compiled
  11.   programs do not run in real-mode, even on x86 under Dos). The
  12.   procedures Intr and MsDos are only supported under DJGPP if
  13.   `__BP_UNPORTABLE_ROUTINES__' is defined (with the
  14.   `-D__BP_UNPORTABLE_ROUTINES__' option). A few other routines are
  15.   also only supported with this define, but on all platforms (but
  16.   they are crude hacks, that's why they are not supported without
  17.   this define).
  18.  
  19. - The internal structure of file variables (TFileRec and TTextRec)
  20.   is different in GPC. However, as far as TFDDs are concerned, there
  21.   are other ways to achieve the same in GPC, see the GPC unit.
  22.  
  23. Copyright (C) 1998-2001 Free Software Foundation, Inc.
  24.  
  25. Author: Frank Heckenbach <frank@pascal.gnu.de>
  26.  
  27. This file is part of GNU Pascal.
  28.  
  29. GNU Pascal is free software; you can redistribute it and/or modify
  30. it under the terms of the GNU General Public License as published by
  31. the Free Software Foundation; either version 2, or (at your option)
  32. any later version.
  33.  
  34. GNU Pascal is distributed in the hope that it will be useful,
  35. but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. GNU General Public License for more details.
  38.  
  39. You should have received a copy of the GNU General Public License
  40. along with GNU Pascal; see the file COPYING. If not, write to the
  41. Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  42. 02111-1307, USA.
  43.  
  44. As a special exception, if you link this file with files compiled
  45. with a GNU compiler to produce an executable, this does not cause
  46. the resulting executable to be covered by the GNU General Public
  47. License. This exception does not however invalidate any other
  48. reasons why the executable file might be covered by the GNU General
  49. Public License.
  50. }
  51.  
  52. {$gnu-pascal,B-,I-}
  53.  
  54. unit WinDos;
  55.  
  56. interface
  57.  
  58. uses GPC, System, Dos;
  59.  
  60. const
  61.   { File attribute constants }
  62.   faReadOnly  = ReadOnly;
  63.   faHidden    = Hidden;    { set for dot files except `.' and `..' }
  64.   faSysFile   = SysFile;   { not supported }
  65.   faVolumeID  = VolumeID;  { not supported }
  66.   faDirectory = Directory;
  67.   faArchive   = Archive;   { means: not executable }
  68.   faAnyFile   = AnyFile;
  69.  
  70.   { Maximum file name component string lengths }
  71.   fsPathName  = 79;
  72.   fsDirectory = 67;
  73.   fsFileName  = 8;
  74.   fsExtension = 4;
  75.  
  76.   { FileSplit return flags }
  77.   fcExtension = 1;
  78.   fcFileName  = 2;
  79.   fcDirectory = 4;
  80.   fcWildcards = 8;
  81.  
  82.   { Flag bit masks -- only used by the unportable Dos routines }
  83.   FCarry     = 1;
  84.   FParity    = 4;
  85.   FAuxiliary = $10;
  86.   FZero      = $40;
  87.   FSign      = $80;
  88.   FOverflow  = $800;
  89.  
  90. type
  91.   PTextBuf = ^TTextBuf;
  92.   TTextBuf = TextBuf;
  93.  
  94.   { Search record used by FindFirst and FindNext }
  95.   TSearchRec = {$ifdef __BP_TYPE_SIZES__} packed {$endif} record
  96.      Fill : SearchRecFill;
  97.      Attr : Byte8;
  98.      Time, Size : LongInt;
  99.      Name : {$ifdef __BP_TYPE_SIZES__}
  100.             packed array [0 .. 12] of Char
  101.             {$else}
  102.             TStringBuf
  103.             {$endif};
  104.      Reserved : SearchRec
  105.   end;
  106.  
  107.   { Date and time record used by PackTime and UnpackTime }
  108.   TDateTime = DateTime;
  109.  
  110.   { 8086 CPU registers -- only used by the unportable Dos routines }
  111.   TRegisters = Registers;
  112.  
  113. var
  114.   { Error status variable }
  115.   DosError : Integer; external;
  116.  
  117. procedure GetDate (var Year, Month, Day, DayOfWeek : Word);    asmname '_p_getdate';
  118. procedure GetTime (var Hour, Minute, Second, Sec100 : Word);   asmname '_p_gettime';
  119. procedure (*@@fjf260*)WGetCBreak (var BreakOn : Boolean);      asmname '_p_getcbreak';
  120. procedure (*@@fjf260*)WSetCBreak (BreakOn : Boolean);          asmname '_p_setcbreak';
  121. procedure (*@@fjf260*)WGetVerify (var VerifyOn : Boolean);     asmname '_p_getverify';
  122. procedure (*@@fjf260*)WSetVerify (VerifyOn : Boolean);         asmname '_p_setverify';
  123. function  DiskFree (Drive : Byte) : LongInt;                   asmname '_p_diskfree';
  124. function  DiskSize (Drive : Byte) : LongInt;                   asmname '_p_disksize';
  125. procedure GetFAttr (var F : GPC_AnyFile; var Attr : Word);     asmname '_p_getfattr';
  126. procedure SetFAttr (var F : GPC_AnyFile; Attr : Word);         asmname '_p_setfattr';
  127. procedure GetFTime (var F : GPC_AnyFile; var aTime : LongInt); asmname '_p_getftime';
  128. procedure SetFTime (var F : GPC_AnyFile; aTime : LongInt);     asmname '_p_setftime';
  129.  
  130. { FindFirst and FindNext are quite inefficient since they emulate
  131.   all the brain-dead Dos stuff. If at all possible, the standard
  132.   routines OpenDir, ReadDir and CloseDir (in the GPC unit) should be
  133.   used instead. }
  134. procedure (*@@fjf260*)WFindFirst (Path : PChar; Attr : Word; var SR : TSearchRec);
  135. procedure (*@@fjf260*)WFindNext  (var SR : TSearchRec);
  136.  
  137. procedure (*@@fjf260*)WFindClose (var SR : TSearchRec);
  138. procedure UnpackTime (P : LongInt; var T : TDateTime);         asmname '_p_unpacktime';
  139. procedure PackTime (const T : TDateTime; var P : LongInt);     asmname '_p_packtime';
  140. function  FileSearch (Dest, Name, List : PChar) : PChar;
  141. function  FileExpand (Dest, Name : PChar) : PChar;
  142. function  FileSplit (Path, Dir, Name, Ext : PChar) : Word;
  143. function  GetCurDir (Dir : PChar; Drive : Byte) : PChar;
  144. procedure SetCurDir (Dir : PChar);
  145. procedure CreateDir (Dir : PChar);
  146. procedure RemoveDir (Dir : PChar);
  147. function  GetArgCount : Integer;
  148. function  GetArgStr (Dest : PChar; ArgIndex : Integer; MaxLen : Word) : PChar;
  149. function  GetEnvVar (VarName : PChar) : PChar;                 asmname '_p_cstringgetenv';
  150.  
  151. {$ifdef __BP_UNPORTABLE_ROUTINES__}
  152. {$ifdef DJGPP}
  153. procedure (*@@fjf260*)WIntr (IntNo : Byte; var Regs : Registers);     asmname '_p_intr';
  154. procedure (*@@fjf260*)WMsDos (var Regs : Registers);                  asmname '_p_msdos';
  155. {$endif}
  156. function  (*@@fjf260*)WDosVersion : Word;                             asmname '_p_dosversion';
  157. procedure (*@@fjf260*)WSetDate (Year, Month, Day : Word);             asmname '_p_setdate';
  158. procedure (*@@fjf260*)WSetTime (Hour, Minute, Second, Sec100 : Word); asmname '_p_settime';
  159. {$endif}
  160.  
  161. implementation
  162.  
  163. procedure DosFindFirst (const Path : String; Attr : Word; var SR : SearchRec); asmname '_p_findfirst';
  164. procedure DosFindNext  (var SR : SearchRec);                                   asmname '_p_findnext';
  165. procedure DosFindClose (var SR : SearchRec);                                   asmname '_p_findclose';
  166.  
  167. procedure ConvertSearchRec (var SR : TSearchRec);
  168. begin
  169.   SR.Attr := SR.Reserved.Attr;
  170.   SR.Time := SR.Reserved.Time;
  171.   SR.Size := SR.Reserved.Size;
  172.   SR.Name := SR.Reserved.Name + #0
  173. end;
  174.  
  175. procedure (*@@fjf260*)WFindFirst (Path : PChar; Attr : Word; var SR : TSearchRec);
  176. begin
  177.   DosFindFirst (CString2String (Path), Attr, SR.Reserved);
  178.   if DosError = 0 then ConvertSearchRec (SR)
  179. end;
  180.  
  181. procedure (*@@fjf260*)WFindNext (var SR : TSearchRec);
  182. begin
  183.   DosFindNext (SR.Reserved);
  184.   if DosError = 0 then ConvertSearchRec (SR)
  185. end;
  186.  
  187. procedure (*@@fjf260*)WFindClose (var SR : TSearchRec);
  188. begin
  189.   DosFindClose (SR.Reserved)
  190. end;
  191.  
  192. function FileSearch (Dest, Name, List : PChar) : PChar;
  193. begin
  194.   FileSearch := CStringLCopy (Dest, FSearch (CString2String (Name), CString2String (List)), fsPathName)
  195. end;
  196.  
  197. function FileExpand (Dest, Name : PChar) : PChar;
  198. begin
  199.   FileExpand := CStringLCopy (Dest, FExpand (CString2String (Name)), fsPathName)
  200. end;
  201.  
  202. function FileSplit (Path, Dir, Name, Ext : PChar) = Res : Word;
  203. var
  204.   d : DirStr;
  205.   n : NameStr;
  206.   e : ExtStr;
  207.   Dummy : CString;
  208. begin
  209.   FSplit (CString2String (Path), d, n, e);
  210.   if Dir  <> nil then Dummy := CStringCopy (Dir,  d);
  211.   if Name <> nil then Dummy := CStringCopy (Name, n);
  212.   if Ext  <> nil then Dummy := CStringCopy (Ext,  e);
  213.   Res := 0;
  214.   if d <> '' then Inc (Res, fcDirectory);
  215.   if n <> '' then Inc (Res, fcFileName);
  216.   if e <> '' then Inc (Res, fcExtension);
  217.   if HasWildCards (n + e) then Inc (Res, fcWildcards)
  218. end;
  219.  
  220. function GetCurDir (Dir : PChar; Drive : Byte) : PChar;
  221. var Path : String (2);
  222. begin
  223.   if Drive = 0 then
  224.     Path := DirSelf
  225.   else
  226.     Path := Succ ('a', Drive - 1) + ':';
  227.   GetCurDir := CStringLCopy (Dir, FExpand (Path), fsDirectory)
  228. end;
  229.  
  230. procedure SetCurDir (Dir : PChar);
  231. begin
  232.   ChDir (CString2String (Dir))
  233. end;
  234.  
  235. procedure CreateDir (Dir : PChar);
  236. begin
  237.   MkDir (CString2String (Dir))
  238. end;
  239.  
  240. procedure RemoveDir (Dir : PChar);
  241. begin
  242.   RmDir (CString2String (Dir))
  243. end;
  244.  
  245. function GetArgCount : Integer;
  246. begin
  247.   GetArgCount := ParamCount
  248. end;
  249.  
  250. function GetArgStr (Dest : PChar; ArgIndex : Integer; MaxLen : Word) : PChar;
  251. begin
  252.   GetArgStr := CStringLCopy (Dest, ParamStr (ArgIndex), MaxLen)
  253. end;
  254.  
  255. end.
  256.